package com.example.notes;

import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;

public class MainActivity extends ActionBarActivity {

	ImageButton btnAdd;
	Button btnRefresh;

	public void getControl() {
		btnAdd = (ImageButton) findViewById(R.id.btnAdd);
		//btnRefresh = (Button) findViewById(R.id.action_refresh);
	}

	public void setEvent() {
		btnAdd.setOnClickListener(new MyProcess());
		//btnRefresh.setOnClickListener(new MyProcess());
	}

	public void InsertNote() {
		Intent i = new Intent(MainActivity.this, InsertNote.class);
		startActivity(i);
	}

	public void RefreshNote() {
		Intent i = new Intent(MainActivity.this, InsertNote.class);
		startActivity(i);
	}

	private class MyProcess implements OnClickListener {

		// create tables
		@Override
		public void onClick(View v) {

			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btnAdd:
				InsertNote();
				break;
			case R.id.action_refresh:
				RefreshNote();
				break;

			}
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		getControl();
		setEvent();

		DatabaseHanler db = new DatabaseHanler(this);
		// Notes n = new Notes("test", "abc", "22:12");
		// db.addNote(n);
		MyAdapter adapter = new MyAdapter(this, db.getNotes());
		ListView lstView = (ListView) findViewById(R.id.lstView);
		lstView.setAdapter(adapter);
		// db.close();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_search) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
